#ifndef __N100_H
#define __N100_H

#include "Headfiles.h"
#include "usart.h"
#include "Motor.h"

extern uint8_t Fd_data[64];
extern uint8_t Fd_rsimu[64];
extern uint8_t Fd_rsahrs[64];
extern uint8_t rs_imutype;
extern uint8_t rs_ahrstype;
extern uint8_t ttl_receive;
extern uint8_t uart3_rx_byte;

extern float yaw_ref;
extern float yaw_mapped, yaw_fixed;
extern uint8_t fix_imu_flag;
extern float Roll_Deg, Pitch_Deg, Yaw_Deg;

//FDlink candata
#define FRAME_HEAD 0xfc
#define FRAME_END 0xfd
#define TYPE_IMU 0x40
#define TYPE_AHRS 0x41
#define TYPE_INSGPS 0x42
#define TYPE_GROUND 0xf0
#define IMU_LEN  0x38   //56+8  8×éÊý¾Ý
#define AHRS_LEN 0x30   //48+8  7×éÊý¾Ý
#define INSGPS_LEN 0x42 //72+8  10×éÊý¾Ý
#define IMU_CAN 9
#define AHRS_CAN 8
#define INSGPS_CAN 11

#define IMU_RS 64
#define AHRS_RS 56
#define INSGPS_RS 80

// IMU 数据结构体
typedef struct
{
    float gyroscope_x;          // rad/s
    float gyroscope_y;
    float gyroscope_z;

    float accelerometer_x;      // m/s^2
    float accelerometer_y;
    float accelerometer_z;

    float magnetometer_x;       // mG
    float magnetometer_y;
    float magnetometer_z;

    float imu_temperature;      // °C
    float Pressure;             // Pa
    float pressure_temperature; // °C

    uint32_t Timestamp;         // us
} IMUData_Packet_t;

// AHRS 数据结构体
typedef struct
{
    float RollSpeed;     // rad/s
    float PitchSpeed;
    float HeadingSpeed;

    float Roll;          // rad
    float Pitch;
    float Heading;

    float Qw;            // Quaternion
    float Qx;
    float Qy;
    float Qz;

    uint32_t Timestamp;  // us
} AHRSData_Packet_t;

// 全局变量声明
extern IMUData_Packet_t IMUData_Packet;
extern AHRSData_Packet_t AHRSData_Packet;

uint32_t timestamp(uint8_t Data_1, uint8_t Data_2, uint8_t Data_3, uint8_t Data_4);
float DATA_Trans(uint8_t Data_1, uint8_t Data_2, uint8_t Data_3, uint8_t Data_4);
void AHRSData2PC(void);
void IMUData2PC(void);

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
uint8_t TTL_Hex2Dec(void);

#endif
